{% include 'QLGL/QLGL_index.html' %}

<div class="am-cf admin-main">
  {% include 'sidebar.html' %}
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">桥梁数据</strong></div>
      </div>
      <div class="am-g" style="position: absolute;height: 100%;right: 0px;left: 260px;width: auto;">

        {% include 'QLGL/QLSJ/QLGL_QLSJ_SIDEBAR.html' %}

        <div class="am-u-sm-10" style="position: absolute;width:auto;right:0;left: 200px;height:85%;overflow-y: scroll;">
          <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">
                <button style="margin: 0 5px" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="back_to()">返回</button>
                <button style="margin: 0 5px" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="add()"><span class="am-icon-plus"></span>新增</button>
                <button style="margin: 0 5px" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="delect()"><span class="am-icon-trash-o"></span> 删除</button>
              </div>
            </div>
          </div>

          <table id="grid" class="am-table am-table-striped am-table-hover table-main am-table-compact am-text-nowrap">
            <thead>
              <tr>
                <th class="table-title"> <input type="checkbox" id="checkAll"  onclick="check_all()"> </th>
                <th class="table-title">部件名称</th>
                <th class="table-title">构件编号</th>
                <th class="table-title">构件名称</th>
              </tr>
            </thead>
            <tbody></tbody>
          </table>



        </div>

      </div>
    </div>
  </div>
</div>
{% include 'footer.html' %}
<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script type="text/javascript" src="/static/assets/js/layer.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<style type="text/css">
  .li_a {
    color: #5c5c5c;
  }
</style>
<script type="text/javascript">
  $("#collapse-nav1").addClass("am-in");
  $("#qlgl").removeClass("am-collapsed");
  $("#qlglOqlsj").css("color", "#3399CC");
  $("#qlgl").css("color", "#3399CC");
  $("#qlsjOqllb").removeClass("li_a");

  var bridge_id = {{ bridge_id | safe }};
      var parts_code = {{ parts_code | safe }};
      var param_bridge_type_code = {{ param_bridge_type_code | safe }};
      var position_code = {{ position_code | safe }};

      function back_to() {
        window.location.href='/QLXJ_QLLB_GJXX_index/?bridge_id=' + bridge_id + '';
      }

      function add() {
        window.location.href = '/QLXJ_QLLB_GJXX_add/?param_bridge_type_code=' + param_bridge_type_code + '&parts_code=' + parts_code + '&bridge_id=' + bridge_id + '&position_code=' + position_code+'';

      }

      function delect() {
        var bridge_member_id = "";
        $("input[name^=Checkbox_number]").each(function() {
          if ($(this).prop('checked')==true) {
            b = $(this).val();
            if(bridge_member_id == ""){
              bridge_member_id =  b;
            }else{
              bridge_member_id = bridge_member_id + '|' + b;
            }
            
          }
        });

        if(bridge_member_id == ""){
          AlertMSG("请选择需要删除的构件！");
          return;
        }

        AMUI.dialog.confirm({
          title: '删除确认',
          content: '您确认删除所选中的构件?',
          onConfirm: function() {
            //console.log('onConfirm,save ' + organize_id);
            $.ajax({
              "url": "/QLXJ_QLLB_GJXX_detail_del/?bridge_member_id=" + bridge_member_id + "",
              "datatype": "json",
              "type": "get",
              "async": "false"
            }).success(function(data) {
              if(data.status == 1) {
                message_layer(data.message)
                window.location.reload();
                // console.log(data.data)
              } else {
                AlertMSG(data.message)
              }
            }).error(function(data) {
              AlertMSG("删除失败！")
            });
          },
          onCancel: function() {
            console.log('onCancel')
          }
        });
      }
// message_layer(data.message)
function message_layer(message){
    layer.msg(message, {
    time: 2000 //2秒关闭（如果不配置，默认是3秒）
  }); 
}

      function check_all() {
        if($("#checkAll").prop('checked') == true) {
          $("input[name^=Checkbox_number]").each(function() {
            $(this).prop('checked', true);
          })
        } else {
          $("input[name^=Checkbox_number]").each(function() {
            $(this).prop('checked', false);
          })
        }
      }
      $(document).ready(function(){
        var t = $('#grid').DataTable({
        //配置DataTables默认参数

        bInfo: true, //页脚信息
        responsive: true,
        searching: true,
        lengthChange: false,
        paging: true,
        bStateSave: true, //保存页面状态
        aoColumnDefs: [{
          "bSortable": false,
          "aTargets": [0]
        }],
        aLengthMenu: [
          [15],
          [15]
        ],

        ajax: {

          url: "/QLXJ_QLLB_GJXX_detail/?bridge_id=" + bridge_id + "&parts_code=" + parts_code + ""
        },

        columns: [

          {
            data: null,
            bSortable: false,
            targets: 0,
            //width : "30px",  
            render: function(data, type, row, meta) {
              return '<input type="checkbox" name="Checkbox_number" class="checkchild"  value=' + row.bridge_member_id + '>';
            }
          },
          {
            "data": "parts_name"
          },
          {
            "data": "member_name"
          },

          {
            "data": "notes"
          }
        ],

        "columnDefs": [
          // "visible": false,
          //"targets": 0

          {
            type: 'chinese-string',
            targets: '_all'
          } //中文排序

        ],


        



      });


        $('#grid tbody').on( 'click', 'tr', function () {
          // $(this).children('td').eq(0).find("input:checkbox").attr("checked");
          // console.log($(this).children('td').eq(0).find("input:checkbox"));
          // console.log($(this).children('td').eq(0));
          var check = $(this).find(".checkchild").prop("checked");
         if(check && check==true){
             $(this).find('.checkchild').prop("checked",false);
             $("#checkAll").prop("checked",false);
        }else{
            $(this).find('.checkchild').prop("checked",true);
        }





        });

        $(document).on("click",".checkchild",function(){
        var check = $(this).prop("checked");
        if(check && check==true){
            $(this).prop("checked",false);
        }else{
            $(this).prop("checked",true);
        }

    });
      })
      




      function popup(title, url) {
        var index = layer.open({
          type: 2,
          title: title,
          content: url,
          area: ['600px', '320px'],

        });

        //铺满界面
        //layer.full(index);
      }

      var AlertMSG = function(msg) {
        AMUI.dialog.alert({
          title: '错误提示',
          content: msg,
          onConfirm: function() {
            console.log('close');
          }
        });
      }
</script>

</body>

</html>